
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<%@ page contentType="text/html; charset=utf-8"%>
	<%@ include file="/commons/taglibs.jsp"%>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
		<title>增加信息终端类型</title>
		<%@ include file="/commons/css_js_head.jsp"%>

<script type="text/javascript" src="${ctx }/js/cascadeConnectionMenu.js"></script>
<script type="text/javascript" src="${ctx }/js/xindiqu.js"></script>
<script type="text/javascript">
	
	window.onload=function(){//页面加载完毕后执行此方法
	//初始化各级联菜单，setDefaultAreaCode方法通过地区码参数指定默认显示的地区
	
	var dq = document.getElementById("userMachineType_dqM").value;
	new CascadeConnectionMenu().setDefaultAreaCode(dq).//默认显示"越秀区",
											initByArray('userMachineType.selA',//内容为省的select元素的name（字符串）或id值
											shengArray,//内容为所有省的数组对象
											'userMachineType.selB',//内容为市的select元素的name（字符串）或id值
											shiArray,//内容为所有市的数组对象
											'userMachineType.selC',//内容为区的select元素的name（字符串）或id值
											quArray);//内容为所有区的数组对象
	}
		
</script>
<script type="text/javascript">
//复写Url
doSaveUrl = "${ctx }/base/userMachineTypeAction!doSave.ts";
doReturnUrl = "${ctx }/base/userMachineTypeAction!doList.ts?code=${code}";



function checkForm(){
	
	if(
		
		checkName() 
		){
		return true;
	}else{
		return false;
	}
}

//保存
function doSave(event) {

	var _form = document.forms[0];
	var doSaveNewUrl=doSaveUrl+"?codeOne="+event;
	if (doSaveUrl == '') {
		alert('请设置正确的URL!');
		return false;
	}
    var txtObj = document.getElementById("userMachineType.name");
    var userMachineType = document.getElementById("userMachineType");
	var tName = txtObj.value;
	if(tName.replace(/[ ]/g,"") == ""){
		var innerHtml = "<span class='ts_red'>请输入名称！<\/span>";
		getFocus(txtObj,userMachineType,innerHtml);
		return false;
	}
	  
	_form.action = doSaveNewUrl;
	_form.submit();
	  
}

function addRowkv() { 
var confName = document.getElementById("confName").value; 
var confValue = document.getElementById("confValue").value; 
 
if(confName.replace(/[ ]/g,"") == "" ){
 alert("请输入正确的名称");
  document.getElementById("confName").focus();
  return false;
}
if(confValue.replace(/[ ]/g,"") == ""){
 alert("请输入名称对应的值");
   document.getElementById("confValue").focus();
   return false;
}

           //添加一行 
var newTr = fzjcTbl.insertRow(fzjcTbl.rows.length-1); 
//添加六列 
var newTd0 = newTr.insertCell(); 
var newTd1 = newTr.insertCell();
var newTd2 = newTr.insertCell(); 
var newTd3 = newTr.insertCell(); 
var newTd4 = newTr.insertCell(); 
var newTd5 = newTr.insertCell(); 
var newTd6 = newTr.insertCell(); 
//设置列内容和属性 

var tname = document.getElementById("confName").value;
var tvalue = document.getElementById("confValue").value;
var confLength1 = document.getElementById("confLength").value;//定义长度
newTd0.innerHTML = '<input type=checkbox  onClick="GetRow()" value="'+confName+"_"+confValue+',"  name="bizNumbershy" align="center" checked="true"/>名称：'; 
newTd1.innerHTML= '<input type=text name="tname" value="'+tname+'"  /><font color="red"></font>';
newTd2.innerHTML= "定义值长度："; 
newTd3.innerHTML= '<input type=text name="diylength" maxlength="2" value="'+confLength1+'"  /><font color="red"></font>';
newTd4.innerHTML= "值："; 
newTd5.innerHTML= '<input type=text name="tvalue" value="'+tvalue+'"  /><font color="red"></font>';
newTd6.innerHTML= "<a href=# onclick='theDelHy()'>删除</a>";

document.getElementById("confName").value="";
document.getElementById("confValue").value="";
document.getElementById("confName").focus();

}

//删除单独一行
function theDelHy(){	
	var fzjcTbl = document.getElementById("fzjcTbl");
	cGetRow=window.event.srcElement.parentElement.parentElement.rowIndex; 
	var ro = fzjcTbl.rows[cGetRow];
	//debugger;
	var rcn = ro.cells[2];
	var rcp = ro.cells[3];
	fzjcTbl.deleteRow(cGetRow);	  				
}
function checkNumber(str)//检查是否为数字
{
    var reg = /^[0-9]+$/;
    if(!reg.test(str))
    {
        return false;
    }
    return true;
}
function validate()
{
   var obj=document.getElementById("confLength");
   if(obj.value=="")
   {
     alert("不能为空!");
     //document.getElementById("confLength").focus();
     return false;
   }
   else
  {
     if(checkNumber(obj.value)==false)
     {
      alert("只能输入数字");
      document.getElementById("confLength").value="";
      //document.getElementById("confLength").focus();
      return false;
      }
    }
}
function valiLength()
{
   
   var confLength1 = document.getElementById("confLength").value;//定义长度
   var confLength2 = document.getElementById("confValue").value.length;//输入长度
   
   
   if(confLength2!=confLength1&&confLength1!="")
   {
      alert("不符合自定义长度!长度应为 "+confLength1+",实际为 "+confLength2);
     document.getElementById("confValue").value="";
     //document.getElementById("confValue").focus();
     return false;
   }
   
}
//验证名称是否存在
function checkUseName()
{
   var name=document.getElementById("name");
   var userMachineType=document.getElementById("userMachineType");
   
   if(name.value == ""){
		var innerHtml = "<span class='ts_red'>请输入名称！<\/span>";
		getFocus(name,userMachineType,innerHtml);
		return false;
	}else{
		$.ajax({
	   		type:"post",
	   		url:"${ctx }/base/userMachineTypeAction!checkName.ts",
	   		cache:false,
	   		data:"&name="+name.value,
	   		success:function(data){
	   			if(data=="true"){
	   				var innerHtml="<span class='ts_red'>该类型名称已存在，请重新输入！<\/span>";
	   				userMachineType.innerHTML=innerHtml;
	   				name.value ="";
	   				name.focus();
	   				return false;
	   			}else{
	   				var innerHtml = "<span class='ts_green'>验证通过，该类型名称可以使用！<\/span>";
	           		userMachineType.innerHTML=innerHtml;
	           		return true;
	   			}
	   		},
	   		error:function(){
	   		    var innerHtml = "<span class='ts_red'>服务繁忙，请稍后再试！<\/span>";
	            userMachineType.innerHTML=innerHtml;
	            name.value = "";
	            return false;
	   		}
   		});
	}
   
}
</script>
	</head>

	<body style="overflow-x: hidden">
		<div class="mTitle">
			<span class="hidsearch"></span>
			<b class="bbig">增加信息终端类型</b> 带
			<b class="fred"> * </b>号为必填项
		</div>

		<form action="/base/userMachineTypeAction" method="post">
		<s:hidden name="userMachineType.dqM"></s:hidden>
			<!--list -->
			<div class="mainAdd">
				<table class="addTable">
					<tr>
						<th>
							<b class="fred"> * </b> 信息终端类型名称：
							
						</th>
						<td >
							<s:textfield name="userMachineType.name" id="name"  maxlength="32" theme="simple" onblur="checkUseName()"/>
							<span id="userMachineType"></span>
						</td >
						
					</tr>
					<tr>
						<th width="10%">
							<b class="fred">*</b>区域：
						</th>
						<td width="40%" colspan="3">
						省：<select name="userMachineType.selA" style="width:140" value="" id="userMachineType_selA"></select>
 			  市：<select name="userMachineType.selB" style="width:140" value="" id="userMachineType.selB"></select>
  			  区：<select name="userMachineType.selC" style="width:140" value="" id="userMachineType.selC"></select>
						</td>
					</tr>
					<tr>
						<th>
							<b class="fred"> * </b> 类型：
						</th>
						<td >
						     <s:select
                                 theme="simple"
                                 name="userMachineType.optionId"
                                 list="#request.list" 
                                 cssStyle="width:83px;"	
                                 listKey="theId" 
                                 listValue="name"
                			     id="select">
							</s:select>
						</td>
						
					</tr>

					 
				<table   class="addTable" id="fzjcTbl">
				
			     		 <tr valign="top">
					        <td width="72" class="td2">自定义名称： </td>
					        <td width="168"><input type="text" name="tname" id="confName"/> <font color="red"></font></td>
					         <td width="72" class="td2">定义值长度： </td>
					        <td width="168"><input type="text" name="diylength" maxlength="3" id="confLength" onblur="return validate()"/> </td>
					        <td width="91" class="td2">值：</td>
					        <td width="168"><input type="text" name="tvalue" id="confValue" onblur="return valiLength()"/> <font color="red"></font></td>
					        <td width="75" class="td2"><input class="btn" type="button"  value="添加值"  onclick="addRowkv();"/></td>
						</tr>
				</table>
			

				</table>
			</div>
			<!--end list -->
			<div class="addToolbar">
				<p>
					<input class="btn" name="btn_confirm" value="确定" type="button"
						onclick="doSave('0');" />
					<input class="btn" name="btn_confirm" value="继续添加" type="button"
						onclick="doSave('1');" />
					<input class="btn" name="btn_return" value="返回" type="button"
						onclick="doReturn();" ; />
				</p>
			</div>

		</form>

	</body>

<script type="text/javascript">
//document.getElementById("options.name").focus();

document.onkeydown = function(e) {
	if (!e)
		e = window.event;//火狐中是 window.event
	if ((e.keyCode || e.which) == 13) {
		doSave();
	}
}
</script>
</html>
